package com.example.ViewPagerSum.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.example.ViewPagerSum.R;
import com.example.ViewPagerSum.domain.MMDetailPthoto;
import com.example.ViewPagerSum.util.URLTools;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * ============================================================
 * author：     王景
 * <p/>
 * time：       2015/9/14  12:46.
 * <p/>
 * email:     wjontheway@163.com
 * <p/>
 * description：   图片详情的适配器
 * <p/>
 * ============================================================
 */
public class PhotoDetailAdapter extends PagerAdapter {

    private MMDetailPthoto mMMDetailPthoto = null;
    private Context context;

    public PhotoDetailAdapter(MMDetailPthoto mMMDetailPthoto, Context context) {
        this.mMMDetailPthoto = mMMDetailPthoto;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mMMDetailPthoto.getSrcList().size();
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    /**
     * @param container
     * @param position
     * @param object    instantiateItem的返回值
     */

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof View) {
            View view = (View) object;
            container.removeView(view);
        }
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.mmphoto_detail, null);
        ImageView imageView = (ImageView) inflate.findViewById(R.id.image);

        String path = URLTools.IMAGRURL + mMMDetailPthoto.getSrcList().get(position);
        Picasso.with(context).load(path).placeholder(R.drawable.ic_launcher).into(imageView);

        container.addView(inflate);
        return inflate;
    }
}
